package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户APP资源控制器。
 */
@RestController
@RequestMapping("images")
public class ImageController {
    @PostMapping
    public Map upload(MultipartFile upload){
        HashMap<String, Object> map = new HashMap<>();
        HashMap<String, String> er = new HashMap<>();
        String url = null;
        try {
            //把图片传到指定的绝对路径上
            url = UploadUtil.uploadQiniu(upload);
            map.put("uploaded", 1);
            map.put("url", url);
        }catch (Exception e){
            e.printStackTrace();
            map.put("uploaded",0);
            er.put("msg","上传失败!");
            map.put("error",er);
        }
        return map;
    }
}
